package com.trsvax.gwthello.components.gwtui;

import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.annotations.AfterRender;
import org.apache.tapestry5.annotations.BeginRender;
import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.trsvax.gwthello.client.GWTUI;
import com.trsvax.gwthello.client.gwtui.services.LineChartService;
import com.trsvax.gwthello.components.GWTComponent;

@IncludeJavaScriptLibrary(value = { "context:/gwtUI/gwtUI.nocache.js" })
public class LineChart extends GWTComponent<GWTUI, LineChartService> implements LineChartService {

	@Parameter(defaultPrefix = "literal")
	@Property
	private String src;

	@Inject
	private ComponentResources componentResources;

	public Class<GWTUI> getGWTModuleClass() {
		return GWTUI.class;
	}

	@BeginRender
	Object begin(MarkupWriter writer) {
		String script = "<script>   var " + getGWTName() + " = {componentIDs: \"\"};";
		script += "var " + getClientID() + " = { " + " completeID: \"" + getCompleteID() + "\"," + " type: \""
				+ "LineChart" + "\"};";
		script += "</script>";

		writer.writeRaw(script);

		writer.element("div", "id", getClientID());

		// return componentResources.getBody();
		return null;
	}

	@AfterRender
	void after(MarkupWriter writer) {
		writer.end();
	}

}
